package com.hotel.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.hotel.bean.Admin;
import com.hotel.exception.SteduException;
import com.hotel.mapper.AdminMapper;
import com.hotel.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin selectUsernamePassword(String username, String password) throws SteduException {
        Admin admin = adminMapper.selectByUsername(username);
        if (admin == null) {
            throw new SteduException("用户名错误");
        }
        String md5Pwd = SecureUtil.md5(password);
        if(!md5Pwd.equals(admin.getPassword())){
            throw new SteduException("密码错误");
        }
        return admin;
    }

    @Override
    public List<Map<String, Object>> selectAllRoomIn() {
        return adminMapper.selectAllRoomIn();
    }

    @Override
    public List<Map<String, Integer>> selectAllRoomRprice() {
        return adminMapper.selectAllRoomRprice();
    }

    @Override
    public Double selectTodayInfo() {
        return adminMapper.selectTodayInfo();
    }
}
